package cn.com.xyc.common;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class FileManageTool {
	public static File FileDown(String picAddress) {
		InputStream is = null;
		OutputStream os = null;
		try {
			URL url = new URL(picAddress);
			is = url.openStream();
			if (is != null) {
				File folder = new File(ApplicationConstants.attachPath);
				if(!folder.exists()){
					folder.mkdirs();
				}
				File file = new File(ApplicationConstants.attachPath+System.currentTimeMillis()+picAddress.substring(picAddress.lastIndexOf(".")));
				os = new FileOutputStream(file);
				int bytesRead=0;
				byte buffer[]=new byte[8192];
				while ((bytesRead=is.read(buffer,0,8192))!=-1){
					os.write(buffer,0,bytesRead);
				}
				os.close();
				is.close();
				return file;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
